/*******************************************************************************
* HEADER
********************************************************************************

Title: 			Norad + GAC combined program analysis

Purpose:		Evaluation paper of the CHAI Nigeria ORS and zinc program

Created by:		Felix Lam

Date created:	December 5, 2017

Description:	The do file loads the Norad and GAC cleaned household datasets and recodes variables in common from both datasets
				to have standardized values. Only variables for indicator analyses are kept and the datasets are appended together. The do file
				conducts descriptive analyses of the key program indicators for each state, by donor-funded states, and for all states in aggregate.

*******************************************************************************/

* Generate single weight variable that combines probability selection weights and post-stratification weights
gen combinedweight=samplingweight*poststratawgt
svyset psu [pw=combinedweight], strata(strata) vce(linearized) || household

* Table 4: descriptive table
svy, subpop(if diarrhea2w==1 & survey==1) : proportion sex
svy, subpop(if diarrhea2w==1 & survey==1) : proportion age
svy, subpop(if diarrhea2w==1 & survey==1) : proportion source
svy, subpop(if diarrhea2w==1 & survey==1) : proportion ors
svy, subpop(if diarrhea2w==1 & survey==1) : proportion zinc
svy, subpop(if diarrhea2w==1 & survey==1) : proportion combined
svy, subpop(if diarrhea2w==1 & survey==1) : proportion respondent_sex
svy, subpop(if diarrhea2w==1 & survey==1) : proportion respondent_age
svy, subpop(if diarrhea2w==1 & survey==1) : proportion education
svy, subpop(if diarrhea2w==1 & survey==1) : proportion rural
svy, subpop(if diarrhea2w==1 & survey==1) : proportion hhsize
svy, subpop(if diarrhea2w==1 & survey==1) : proportion water
svy, subpop(if diarrhea2w==1 & survey==1) : proportion state
svy, subpop(if diarrhea2w==1 & survey==1) : proportion wealth

svy, subpop(if diarrhea2w==1 & survey==2) : proportion sex
svy, subpop(if diarrhea2w==1 & survey==2) : proportion age
svy, subpop(if diarrhea2w==1 & survey==2) : proportion source
svy, subpop(if diarrhea2w==1 & survey==2) : proportion ors
svy, subpop(if diarrhea2w==1 & survey==2) : proportion zinc
svy, subpop(if diarrhea2w==1 & survey==2) : proportion combined
svy, subpop(if diarrhea2w==1 & survey==2) : proportion respondent_sex
svy, subpop(if diarrhea2w==1 & survey==2) : proportion respondent_age
svy, subpop(if diarrhea2w==1 & survey==2) : proportion education
svy, subpop(if diarrhea2w==1 & survey==2) : proportion rural
svy, subpop(if diarrhea2w==1 & survey==2) : proportion hhsize
svy, subpop(if diarrhea2w==1 & survey==2) : proportion water
svy, subpop(if diarrhea2w==1 & survey==2) : proportion state
svy, subpop(if diarrhea2w==1 & survey==2) : proportion wealth

svy, subpop(if diarrhea2w==1 & survey==3) : proportion sex
svy, subpop(if diarrhea2w==1 & survey==3) : proportion age
svy, subpop(if diarrhea2w==1 & survey==3) : proportion source
svy, subpop(if diarrhea2w==1 & survey==3) : proportion ors
svy, subpop(if diarrhea2w==1 & survey==3) : proportion zinc
svy, subpop(if diarrhea2w==1 & survey==3) : proportion combined
svy, subpop(if diarrhea2w==1 & survey==3) : proportion respondent_sex
svy, subpop(if diarrhea2w==1 & survey==3) : proportion respondent_age
svy, subpop(if diarrhea2w==1 & survey==3) : proportion education
svy, subpop(if diarrhea2w==1 & survey==3) : proportion rural
svy, subpop(if diarrhea2w==1 & survey==3) : proportion hhsize
svy, subpop(if diarrhea2w==1 & survey==3) : proportion water
svy, subpop(if diarrhea2w==1 & survey==3) : proportion state
svy, subpop(if diarrhea2w==1 & survey==3) : proportion wealth

tabulate survey, gen(survey_c)
svy, subpop(if survey==1 | survey==3):tab diarrhea2w survey_c3, pearson col

svy, subpop(if diarrhea2w==1 & (survey==1 | survey==3)):tab sex survey_c3, pearson col

tabulate age, gen(age_c)
svy, subpop(if diarrhea2w==1 & (survey==1 | survey==3)):tab age_c1 survey_c3, pearson col
svy, subpop(if diarrhea2w==1 & (survey==1 | survey==3)):tab age_c2 survey_c3, pearson col
svy, subpop(if diarrhea2w==1 & (survey==1 | survey==3)):tab age_c3 survey_c3, pearson col
svy, subpop(if diarrhea2w==1 & (survey==1 | survey==3)):tab age_c4 survey_c3, pearson col
svy, subpop(if diarrhea2w==1 & (survey==1 | survey==3)):tab age_c5 survey_c3, pearson col

tab source, gen(source_c)
svy, subpop(if diarrhea2w==1 & (survey==1 | survey==3)):tab source_c1 survey_c3, pearson col
svy, subpop(if diarrhea2w==1 & (survey==1 | survey==3)):tab source_c2 survey_c3, pearson col
svy, subpop(if diarrhea2w==1 & (survey==1 | survey==3)):tab source_c3 survey_c3, pearson col
svy, subpop(if diarrhea2w==1 & (survey==1 | survey==3)):tab source_c4 survey_c3, pearson col
svy, subpop(if diarrhea2w==1 & (survey==1 | survey==3)):tab source_c5 survey_c3, pearson col
	
svy, subpop(if diarrhea2w==1 & (survey==1 | survey==3)):tab ors survey_c3, pearson col
svy, subpop(if diarrhea2w==1 & (survey==1 | survey==3)):tab combined survey_c3, pearson col
svy, subpop(if diarrhea2w==1 & (survey==1 | survey==3)):tab respondent_sex survey_c3, pearson col

tab respondent_age, gen(respondent_age_c)
svy, subpop(if diarrhea2w==1 & (survey==1 | survey==3)):tab respondent_age_c1 survey_c3, pearson col
svy, subpop(if diarrhea2w==1 & (survey==1 | survey==3)):tab respondent_age_c2 survey_c3, pearson col
svy, subpop(if diarrhea2w==1 & (survey==1 | survey==3)):tab respondent_age_c3 survey_c3, pearson col
svy, subpop(if diarrhea2w==1 & (survey==1 | survey==3)):tab respondent_age_c4 survey_c3, pearson col
svy, subpop(if diarrhea2w==1 & (survey==1 | survey==3)):tab respondent_age_c5 survey_c3, pearson col
svy, subpop(if diarrhea2w==1 & (survey==1 | survey==3)):tab respondent_age_c6 survey_c3, pearson col

svy, subpop(if diarrhea2w==1 & (survey==1 | survey==3)):tab education survey_c3, pearson col
svy, subpop(if diarrhea2w==1 & (survey==1 | survey==3)):tab rural survey_c3, pearson col

tab hhsize, gen(hhsize_c)
svy, subpop(if diarrhea2w==1 & (survey==1 | survey==3)):tab hhsize_c1 survey_c3, pearson col
svy, subpop(if diarrhea2w==1 & (survey==1 | survey==3)):tab hhsize_c2 survey_c3, pearson col
svy, subpop(if diarrhea2w==1 & (survey==1 | survey==3)):tab hhsize_c3 survey_c3, pearson col
svy, subpop(if diarrhea2w==1 & (survey==1 | survey==3)):tab hhsize_c4 survey_c3, pearson col

svy, subpop(if diarrhea2w==1 & (survey==1 | survey==3)):tab water survey_c3, pearson col

tab state, gen(state_c)
svy, subpop(if diarrhea2w==1 & (survey==1 | survey==3)):tab state_c1 survey_c3, pearson col
svy, subpop(if diarrhea2w==1 & (survey==1 | survey==3)):tab state_c2 survey_c3, pearson col
svy, subpop(if diarrhea2w==1 & (survey==1 | survey==3)):tab state_c3 survey_c3, pearson col
svy, subpop(if diarrhea2w==1 & (survey==1 | survey==3)):tab state_c4 survey_c3, pearson col
svy, subpop(if diarrhea2w==1 & (survey==1 | survey==3)):tab state_c5 survey_c3, pearson col
svy, subpop(if diarrhea2w==1 & (survey==1 | survey==3)):tab state_c6 survey_c3, pearson col
svy, subpop(if diarrhea2w==1 & (survey==1 | survey==3)):tab state_c7 survey_c3, pearson col
svy, subpop(if diarrhea2w==1 & (survey==1 | survey==3)):tab state_c8 survey_c3, pearson col

tab wealth, gen(wealth_c)
svy, subpop(if diarrhea2w==1 & (survey==1 | survey==3)):tab wealth_c1 survey_c3, pearson col
svy, subpop(if diarrhea2w==1 & (survey==1 | survey==3)):tab wealth_c2 survey_c3, pearson col
svy, subpop(if diarrhea2w==1 & (survey==1 | survey==3)):tab wealth_c3 survey_c3, pearson col
svy, subpop(if diarrhea2w==1 & (survey==1 | survey==3)):tab wealth_c4 survey_c3, pearson col
svy, subpop(if diarrhea2w==1 & (survey==1 | survey==3)):tab wealth_c5 survey_c3, pearson col

* Table 5 - Seeking care by selected characteristics and bivariate results (logistic)
svy, subpop(if diarrhea2w==1) : proportion seekcare, over(survey)

xtgee seekcare i.survey i.sex i.age i.respondent_sex i.respondent_age i.education i.rural i.hhsize i.water i.state i.wealth if diarrhea2w==1 [pw=combinedweight], link(logit) family(binomial) i(psu) eform
margins survey
marginsplot, xdimension(survey) yscale(range(.6 .8)) ylabel(.6(.05).8)
graph save Graph "Figures/Seekcare marginsplot_GEEPooled.gph", replace
contrast r.survey
contrast ar.survey

* Table 6 without interaction - ORS coverage by selected characteristics and bivariate results (GEE)
xtgee ors i.survey i.sex i.age i.source i.respondent_sex i.respondent_age i.education i.rural i.hhsize i.water i.state i.wealth if diarrhea2w==1 [pw=combinedweight], link(logit) family(binomial) i(psu) eform
margins survey, saving(ors, replace)
marginsplot, xdimension(survey) yscale(range(0 .6)) ylabel(.1(.1).6)
graph save Graph "Figures/ORS marginsplot_GEEPooled.gph", replace
contrast r.survey
contrast ar.survey

xtgee combined i.survey i.sex i.age i.source i.respondent_sex i.respondent_age i.education i.rural i.hhsize i.water i.state i.wealth if diarrhea2w==1 [pw=combinedweight], link(logit) family(binomial) i(psu) eform
margins survey, saving(combined, replace)
marginsplot, xdimension(survey) yscale(range(0 .6)) ylabel(.1(.1).6)
graph save Graph "Figures/Combined marginsplot_GEEPooled.gph", replace
contrast r.survey
contrast ar.survey

combomarginsplot ors combined, labels("ORS" "Combined ORS and Zinc")
graph save Graph "Figures/Figure 2.gph", replace

* Table 6 with interaction - ORS coverage by selected characteristics and bivariate results (GEE)
xtgee ors i.survey##i.source i.sex i.age i.respondent_sex i.respondent_age i.education i.rural i.hhsize i.water i.state i.wealth if diarrhea2w==1 [pw=combinedweight], link(logit) family(binomial) i(psu) eform
margins, dydx(survey) over(source)
marginsplot, xdimension(survey) yscale(range(0 .6)) ylabel(.1(.1).6)
graph save Graph "Figures/ORSxSource Interaction marginsplot_GEEPooled.gph", replace

xtgee combined i.survey##i.source i.sex i.age i.respondent_sex i.respondent_age i.education i.rural i.hhsize i.water i.state i.wealth if diarrhea2w==1 [pw=combinedweight], link(logit) family(binomial) i(psu) eform
margins, dydx(survey) over(source)
marginsplot, xdimension(survey) yscale(range(0 .6)) ylabel(.1(.1).6)
graph save Graph "Figures/CombinedxSource Interaction marginsplot_GEEPooled.gph", replace
